function renderModel(response) {
    if (response.data == null) return false;
    var modelAttr = 'model'
        , fatherElem = 'body',
        data = response.data;
    if (response.attr != null) modelAttr = response.attr;
    if (response.elem != null) fatherElem = response.elem;

    document.querySelectorAll(fatherElem + ' [' + modelAttr + ']').forEach(element => {
        var key = element.getAttribute(modelAttr), nodeName = element.tagName;
        if (nodeName == 'INPUT') {
            if (data[key] != null) element.setAttribute('value', data[key]);
        } else if (nodeName == 'IMG') {
            if (data[key] != null) element.setAttribute('src', data[key]);
        } else {
            if (data[key] != null) element.innerText = data[key];
        }
    });
}


function getModel(response) {
    var modelAttr = 'model'
        , fatherElem = 'body';
    if (response.attr != null) modelAttr = response.attr;
    if (response.elem != null) fatherElem = response.elem;
    var data = {};
    document.querySelectorAll(fatherElem + ' [' + modelAttr + ']').forEach(element => {
        var key = element.getAttribute(modelAttr), nodeName = element.tagName;
        if (nodeName == 'INPUT' || nodeName == 'SELECT' || nodeName == 'TEXTAREA') {
            if(element.type == "radio"){
                data[key] = document.querySelector(fatherElem + ' [' + modelAttr + ']:checked').value;
            }else{
                data[key] = element.value;
            }
        } else if (nodeName == 'IMG') {
            data[key] = element.getAttribute('src');
        } else {
            data[key] = element.innerText;
        }
    });
    return data;
}
